﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace XFControls
{
    public partial class XFCheckBox : UserControl
    {
        //flag to indicate the pressed state
        private System.ComponentModel.ComponentResourceManager Resources = new System.ComponentModel.ComponentResourceManager(typeof(XFCheckBox));

        public Boolean Checked = true;
        
        private Boolean Clicked;

        public XFCheckBox()
        {
            InitializeComponent();
        }

        private void picture_Click(object sender, EventArgs e)
        {
            if (Checked)
            {
                this.picture.Image = ((System.Drawing.Image)(Resources.GetObject("cb_unchecked")));
                this.picture.Invalidate();
                Checked = false;
            }
            else
            {
                this.picture.Image = ((System.Drawing.Image)(Resources.GetObject("cb_checked")));
                this.picture.Invalidate();
                Checked = true;
            }
            Clicked = true;
        }

        private void picture_MouseDown(object sender, MouseEventArgs e)
        {
            this.picture.Image = ((System.Drawing.Image)(Resources.GetObject("cb_check")));
            this.Invalidate();
        }

        private void picture_MouseUp(object sender, MouseEventArgs e)
        {
            if (!Clicked)
            {
                if (Checked)
                {
                    this.picture.Image = ((System.Drawing.Image)(Resources.GetObject("cb_checked")));
                    this.Invalidate();
                }
                else
                {
                    this.picture.Image = ((System.Drawing.Image)(Resources.GetObject("cb_unchecked")));
                    this.Invalidate();
                }
            }
            else
            {
                Clicked = false;
            }
        }
    }
}
